<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {include file="/layout/scriptload"}
    <title>回复消息库</title>
</head>
<body>
<div id="app">
    <el-header style="line-height: 60px;height: 30px;">
        消息回复管理 > 回复消息库
    </el-header>
    <el-container>
        <el-main>
            <el-row>
                <el-col :span="6" style="margin-right: 10px;">
                    <el-input v-model="keyword" placeholder="回复消息标题">
                        <el-button @click="get_list()" slot="append">搜索</el-button>
                    </el-input>
                </el-col>
                <el-col :span="12">
                    <el-button @click="refresh()" type="primary" icon="el-icon-refresh"></el-button>
                    <el-button @click="handle_msg()" type="primary">添加回复消息</el-button>
                </el-col>
            </el-row>
            <el-row>
                <el-table :data="table_data" border stripe style="margin-top: 10px;">
                    <el-table-column prop="type" label="消息类型" width="100"></el-table-column>
                    <el-table-column prop="is_normal" label="是否普通回复" width="150">
                        <template slot-scope="scope">
                            <span v-if="scope.row.is_normal" style="color: #409eff; font-weight: bold">是</span>
                            <span v-else style="color: gray">否</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="is_subscribe" label="是否关注回复" width="150">
                        <template slot-scope="scope">
                            <span v-if="scope.row.is_subscribe" style="color: #409eff; font-weight: bold">是</span>
                            <span v-else style="color: gray">否</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="is_keyword" label="是否关键字回复" width="150">
                        <template slot-scope="scope">
                            <span v-if="scope.row.is_keyword" style="color: #409eff; font-weight: bold">是</span>
                            <span v-else style="color: gray">否</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="name" label="回复消息标题" width="180"></el-table-column>
                    <el-table-column prop="createtime" label="创建时间" width="180"></el-table-column>
                    <el-table-column prop="operation" label="更多操作" width="200">
                        <template slot-scope="scope">
                            <el-button size="small" type="primary" @click="handle_msg(scope.row.id)">编辑</el-button>
                            <el-button size="small" type="danger" @click="del_msg(scope.row.id)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-row>
        </el-main>
    </el-container>
</div>
</body>
<script>
    var vm = new Vue({
        el: '#app',
        data: {
            keyword: '',
            table_data: [], // 表格数据
        },
        methods: {
            // 获取数据
            get_list() {
                var that = this;
                $.ajax({
                    type: 'post',
                    cache: false,
                    url: '{:url("reply.index/get_msg_list")}',
                    data: {keyword: that.keyword},
                    success: function (res) {
                        that.table_data = res;
                    },
                    error: function () {
                        layerAlert('发生系统错误,请与管理员联系！');
                    }
                });
            },
            // 刷新数据
            refresh() {
                this.keyword = '';
                this.get_list();
            },
            // 打开处理回复消息界面
            handle_msg(msgid = null) {
                url = "{:url('reply.index/handle_msg_view')}" + "?msgid=" + msgid;
                layerWindow('添加回复消息', url, '70%', '65%');
            },
            // 删除回复消息
            del_msg(msgid) {
                var that = this;
                that.$confirm('删除此消息?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    $.ajax({
                        type: 'post',
                        cache: false,
                        url: "{:url('reply.index/del_msg')}" + "?msgid=" + msgid,
                        success: function (res) {
                            if (res) {
                                that.$message({
                                    type: 'success',
                                    message: '删除成功!'
                                });
                                that.refresh();
                            } else {
                                that.$message.error('删除失败');
                            }
                        },
                        error: function () {
                            layerAlert('系统错误,请联系管理员');
                        }
                    });
                });
            },
        }
    });
    vm.get_list();
</script>
</html>